﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XiTi
{
    public class Content
    {
        public string head_title;
        public List<Question> questions;
    }
    public class Meat
    {
        public string pid;
        public string title;
    }
    public class Paper
    {
        public Meat _meta;
        public List<Content> content;

        public string TakeAnswerHtml()
        {
            string[] d1 = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
            StringBuilder sb = new StringBuilder();
            sb.Append("<!DOCTYPE html><html lang='zh'><head><meta charset='UTF-8'><title>习题答案</title></head><body><p>\n");

            int idx = 1;
            for (int j = 0; j < content.Count; j++)
            {
                var c = content[j];
                sb.Append("<p class='content'>\n");
                sb.Append("<p class='head_title'>").Append(d1[j]).Append("、").Append(c.head_title).Append("</p>\n");
                var qs = c.questions;
                for (int i = 0; i < qs.Count; i++)
                {
                    Question q = qs[i];

                    sb.Append("<p class='question'>");
                    sb.Append(JsonHelper.question2Html(q, idx.ToString() + ". "));

                    if (q.qa != null && q.qa.data != null)
                    {
                        sb.Append("<p>").Append(idx.ToString()).Append(".</p>");
                        if (!string.IsNullOrEmpty(q.qa.data.answer))
                        {
                            sb.Append("<p><img src='").Append(q.qa.data.answer).Append("'></p>");
                        }
                        if (q.qa.data.list != null)
                        {
                            foreach(var d in q.qa.data.list)
                            {
                                sb.Append("<p><img src='").Append(d.answer).Append("'></p>");
                            }
                        }
                    }
                    
                    idx++;
                    sb.Append("</p>\n");
                }
                sb.Append("</p>\n");
            }
            sb.Append("</p></body></html>");
            return sb.ToString();
        }

        public string TakeHtml()
        {
            string[] d1 = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
            StringBuilder sb = new StringBuilder();
            sb.Append("<!DOCTYPE html><html lang='zh'><head><meta charset='UTF-8'><title>物理习题</title></head><body><p>\n");

            int idx = 1;
            for (int j=0; j<content.Count; j++)
            {
                var c = content[j];
                sb.Append("<p class='content'>\n");
                sb.Append("<p class='head_title'>").Append(d1[j]).Append("、").Append(c.head_title).Append("</p>\n");
                var qs = c.questions;
                for (int i = 0; i < qs.Count; i++)
                {
                    Question q = qs[i];
                    sb.Append("<p class='question'>");
                    sb.Append(JsonHelper.question2Html(q, idx.ToString() + ". "));
                    idx++;
                    sb.Append("</p>\n");
                }
                sb.Append("</p>\n");
            }
            sb.Append("</p></body></html>");
            return sb.ToString();
        }

        public string TakeJson()
        {
            return "";
        }
    }
}
